$("#sx1").click(function () {
    window.location = 'userLoginLog.html';
})

$("#tabuserlog").hide();
$("#tabAdministratorLoginLog").hide();

var administratorLoginLogtableI = null;
function  administratorLoginLogtableRefre(){
    administratorLoginLogtableI.reload('administratorLoginLogtableId');
}
var userLoginLogtableI = null;
function  userLoginLogtableRefre(){
    userLoginLogtableI.reload('userLoginLogtableId');
}

layui.use(['table', 'form'], function(){
        table = layui.table,
        form = layui.form;



    if($("#tabAdministratorLoginLog").html() == "administratorlog"){
        administratorLoginLogtableI = table.render({
            elem: '#test',
            url:'/administratorLoginLog/getAll',
            id:'administratorLoginLogtableId',
            page:{
                layout:['count','prev','page','next','limit'],
                groups:5,
                limit:10,
                limits:[10,15,20]

            },
            cols: [[
                {type: 'checkbox',width: 50},
                {field:'loginLogId', width: 70, title: '序号',align:'center'},
                {field:'logLoginAddress', width: 200, title: '登录地址',align:'center'},
                {field:'logLoginIp', width: 200, title: '登录IP',align:'center'},
                {field:'logOrderSource', width: 200, title: '订单来源',align:'center'},
                {field:'logLoginTime', title: '登陆时间',  width: 250,align:'center'},
                {field:'logLoginName', title: '名称',  width: 150,align:'center'},
                {field:'logLoginAccount', title: '账号',  width: 150,align:'center'},
                {fixed: '', title:'操作', toolbar: '#barDemo',minWidth:80,align:'center'}
            ]],
            toolbar:'#toolbarDemo',
            skin: 'line',
            parseData:function (res){
                return{
                    "code":res.code, // 解析接口状态
                    "msg": res.msg, // 解析提示文本
                    "count": res.count, // 解析总条数
                    "data": res.data // 解析数据列表
                };
            }
        });

        form.on('submit(go)',function (d){
            d = d.field;
            console.log(d);
            table.reload('administratorLoginLogtableId',{
                where:{
                    logLoginName:d.logLoginName,
                    logLoginAccount:d.logLoginAccount
                }
            });
        })
    }else {
        userLoginLogtableI = table.render({
            elem: '#test',
            url:'/administratorLoginLog/usergetAll',
            id:'userLoginLogtableId',
            page:{
                layout:['count','prev','page','next','limit'],
                groups:5,
                limit:10,
                limits:[10,15,20]

            },
            cols: [
                [
                {type: 'checkbox',width: 50},
                {field:'loginLogId', width: 70, title: '序号',align:'center'},
                {field:'logLoginAddress', width: 200, title: '登录地址',align:'center'},
                {field:'logLoginIp', width: 200, title: '登录IP',align:'center'},
                {field:'logOrderSource', width: 200, title: '订单来源',align:'center'},
                {field:'logLoginTime', title: '登陆时间',  width: 250,align:'center'},
                {field:'logLoginName', title: '名称',  width: 150,align:'center'},
                {field:'logLoginAccount', title: '账号',  width: 150,align:'center'},
                {fixed: '', title:'操作', minWidth:80,toolbar: '#barDemo',align:'center'}
            ]
            ],
            toolbar:'#toolbarDemo',
            parseData:function (res){
                return{
                    "code":res.code, // 解析接口状态
                    "msg": res.msg, // 解析提示文本
                    "count": res.count, // 解析总条数
                    "data": res.data // 解析数据列表
                };
            }
        });


        form.on('submit(goo)',function (d){
            d = d.field;
            console.log(d);
            table.reload('userLoginLogtableId',{
                where:{
                    logLoginName:d.logLoginName,
                    logLoginAccount:d.logLoginAccount
                }
            });
        })
    }
    table.on('tool(test)', function(obj){ // 双击 toolDouble
        data = obj.data;
        //console.log(obj)
        if(obj.event === 'del'){
            layer.confirm('真的删除行么', function(){
                // layer.close(index);
                $.ajax({
                    type:"post",
                    url:'/administratorLoginLog/del',
                    data: {"loginLogId":data.loginLogId},
                    dataType:'json',
                    success:function (res) {
                        if (res.state == 200){
                            layer.msg(res.msg,{time:500,icon:6})
                            if($("#tabAdministratorLoginLog").html() == "administratorlog"){
                                administratorLoginLogtableRefre();
                            }else {
                                userLoginLogtableRefre();
                            }
                        }
                        else {
                            layer.msg(res.msg,{time:500,icon:5})
                        }
                    },
                    error:function(e){
                        console.log("异常");

                    }

                })

            });
        }

    });




});
